package com.huaxingbankas.modules.action;

import java.util.List;
import javax.annotation.Resource;


import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;

import com.huaxingbankas.core.base.action.BaseAction;
import com.huaxingbankas.modules.model.Users;
import com.huaxingbankas.modules.services.UsersServices;
import com.opensymphony.xwork2.ActionContext;

@ParentPackage("json-default") 
@Controller
public class AdminUserManage extends BaseAction {
	static Logger logger = Logger.getLogger(AdminUserManage.class.getName());
	private static final long serialVersionUID = 1L;
	@Resource
    private UsersServices userservice;
	private Users currentUser;
	private String chineseName;
	private String j_username;
	private String j_password;

	public String getUsername() {
		return j_username;
	}

	public void setUsername(String username) {
		this.j_username = username;
	}

	public String getPassword() {
		return j_password;
	}

	public void setPassword(String password) {
		this.j_password = password;
	}
	public String getChineseName() {
		return chineseName;
	}
	public void setChineseName(String chineseName) {
		this.chineseName = chineseName;
	}
	public Users getCurrentUser() {
		return currentUser;
	}
	public void setCurrentUser(Users currentUser) {
		this.currentUser = currentUser;
	}
	private List<Users> usersList;
	public List<Users> getUsers() {
		return usersList;
	}
	public void setUsers(List<Users> users) {
		this.usersList = users;
	}
	@Action(value = "/adminUserManage", results = { @Result(name = SUCCESS, location = "admin/userList.jsp") })
	@Override
	public String execute() {
		UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext()
			    .getAuthentication()
			    .getPrincipal();
		usersList = this.userservice.findAll();
		logger.error("pring username value ====="+ userDetails.getUsername());
		currentUser = this.userservice.findByUsername(userDetails.getUsername());
		ActionContext.getContext().getSession().put("chineseName", currentUser.getName());
		
		httpServletRequest.setAttribute("usersList", usersList);
		for (Users users:usersList){
			System.out.println("name =" + users.getName() + " username = " + users.getUsername() + " password= " + users.getPassword() );
		}
	return SUCCESS;
	}


	
	
}
